package com.marketlive.app.b2c.nav;

/*
 (C) Copyright MarketLive. 2006. All rights reserved.
 MarketLive is a trademark of MarketLive, Inc.
 Warning: This computer program is protected by copyright law and international treaties.
 Unauthorized reproduction or distribution of this program, or any portion of it, may result
 in severe civil and criminal penalties, and will be prosecuted to the maximum extent
 possible under the law.
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.marketlive.entity.IEntity;
import org.marketlive.entity.IEntityNamePage;

import com.marketlive.app.b2c.NavState;

/**
 * Abstract base class for URL link generator.
 * Provides entity URL generation and path URL generation with
 * NavState-encoded parameterization.
 * Provides overriden methods available for RSS Feed URLs.
 */
public abstract class BaseLinkGenerator implements ILinkGenerator {

    // Array of link generation prefences. Entries have priority
    // based on their position in the array.
    //
    // Default to ID-based generation.
    //
    protected int[] generationPreference = new int[] { URI_BY_URL_VALUE, URI_BY_NAME, URI_BY_ID };
    // Should the link contain the full category path?
    protected boolean includePath = true;

    public boolean isIncludePath(){
        return this.includePath;
    }
    
    public void setIncludePath(boolean includePath){
        this.includePath = includePath;
    }
    /**
     * Wraps (prepends) the given URI with the specified Locale's code (e.g: fr_ca, es), in lowercase. If the specified
     * locale is the default locale for the specified site, then the locale code is not prepended.
     *
     * @param uri
     * @param site
     * @param locale
     */
    public String wrapURI(String uri, Locale locale) {

        if (uri == null) {
            return "";
        }
        StringBuffer sb = new StringBuffer(uri);

        Locale siteDefaultLocale = new Locale("en", "US");

        if (!locale.equals(siteDefaultLocale)) {
            sb.insert(0, "/" + locale.toString().toLowerCase());
        }

        return sb.toString();
    }

}
